<?php
include('session.php');
include('Template/_meta.html');
include('charts.php');

?>
<title>我的桌面</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/materialdesignicons.min.css" rel="stylesheet">
<link href="css/style.min.css" rel="stylesheet">
</head>

<body>
<div class="page-container">
 <div class="row" >
          <div class="col-sm-6 col-lg-3" style="width:250px">
            <div class="card bg-primary">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">今日充值</p>
                  <p class="h3 text-white m-b-0">
                <?php
                if ($status == 0) {
                    $q="SELECT sum(money) AS count FROM pay_log where TO_DAYS(time)=TO_DAYS(NOW())";
                    }
                    elseif($status == 1){
                    $q="SELECT sum(money) AS count FROM pay_log where TO_DAYS(time)=TO_DAYS(NOW()) and fuser<>'admin' and (code='$code'  or fuser='$_SESSION[username]' or fuser_1='$_SESSION[username]')";
                    }
                    elseif($status == 2){
                    $q="SELECT sum(money) AS count FROM pay_log where TO_DAYS(time)=TO_DAYS(NOW()) and fuser<>'admin' and (code='$code'  or fuser='$_SESSION[username]')";
                    }elseif($status == 3){
                    $q="SELECT sum(money) AS count FROM pay_log where TO_DAYS(time)=TO_DAYS(NOW()) and code='$code' and fuser<>'admin'";    
                    }
				$result=mysql_fetch_array(mysql_query($q));
				$count=$result['count'];
				
				if ($count == null){
				    echo "0";
				}
				echo" $count " ;
                ?>
                  </p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-currency-cny fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3" style="width:250px">
            <div class="card bg-danger">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">今日注册</p>
                  <p class="h3 text-white m-b-0">
                    <?php
                    if ($status == 0) {
                    $q="SELECT count(id) AS count FROM game_user where TO_DAYS(logtime)=TO_DAYS(NOW()) and fuser<>'admin'";
                    }else{
                    $q="SELECT count(id) AS count FROM game_user where TO_DAYS(logtime)=TO_DAYS(NOW()) and (code='$code' or fuser='$_SESSION[username]')";
                    }
				$result=mysql_fetch_array(mysql_query($q));
				$count=$result['count'];
				echo" $count " 
				
                ?>  
                  </p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3" style="width:250px">
            <div class="card bg-success">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">充值总额</p>
                  <p class="h3 text-white m-b-0">
                      <?php
                    if ($status == 0) {
                    $q="SELECT sum(money) AS count FROM pay_log where fuser<>'admin'";
                    }elseif ($status == 1){
                    $q="SELECT sum(money) AS count FROM pay_log WHERE fuser<>'admin' and (code='$code' or fuser='$_SESSION[username]' or fuser_1='$_SESSION[username]')";
                    }elseif ($status == 2){
                    $q="SELECT sum(money) AS count FROM pay_log WHERE fuser<>'admin' and (code='$code' or fuser='$_SESSION[username]')";
                    }elseif ($status == 3){
                    $q="SELECT sum(money) AS count FROM pay_log WHERE code='$code' and fuser<>'admin'";
                    }   
				$result=mysql_fetch_array(mysql_query($q));
				$count=$result['count'];
				if ($count == ""){
				    echo "0";
				}
				echo" $count ";
				
                ?>
                      </p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-currency-cny fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
          
          <div class="col-sm-6 col-lg-3" style="width:250px">
            <div class="card bg-purple">
              <div class="card-body clearfix">
                <div class="pull-right">
                  <p class="h6 text-white m-t-0">注册总数</p>
                  <p class="h3 text-white m-b-0">
                    <?php
                if ($status == 0) {
                    $q="SELECT count(id) AS count FROM game_user";
                    }else{
                    $q="SELECT count(id) AS count FROM game_user WHERE code='$code' or fuser='$_SESSION[username]'";
                    }    
				$result=mysql_fetch_array(mysql_query($q));
				$count=$result['count'];
				echo" $count " 
				
                ?>    
                  </p>
                </div>
                <div class="pull-left"> <span class="img-avatar img-avatar-48 bg-translucent"><i class="mdi mdi-account fa-1-5x"></i></span> </div>
              </div>
            </div>
          </div>
        </div>
        
    </div>

<footer class="footer mt-20">
    
</footer>
<div class="page-container">
	<div class="mt-20">
		<table class="table table-border table-bordered table-bg table-hover table-sort table-responsive">
			<thead>
				<tr class="text-c">
					<th width="50">代理账号</th>
					<th width="50">代理等级</th>
					<th width="50">今日充值（含下级代理）</th>
					<th width="50">今日充值（不含下级代理）</th>
					<th width="50">当天分成</th>
					<th width="50">分成总额</th>
					<th width="50">已结算金额</th>
					<th width="50">未结算金额</th>
				</tr>
			</thead>
			<tbody>
			
				
<?php       
            if ($status == 0 ){
            $sql ="select * from user where username<>'admin'";
            }else{
			$sql="select * from user where guishu='$_SESSION[username]' or username='$_SESSION[username]' ";
            }
            $user = array();
			$result = mysql_query($sql);
			while($row=mysql_fetch_assoc($result))
			{ 
			    
			    $user[]=$row;
			     
			}
			
			foreach ($user as $values){
			 $sql = "SELECT sum(money) AS count FROM pay_log where TO_DAYS(time)=TO_DAYS(NOW()) and fuser<>'admin' and (code='$values[daili]' or fuser='$values[username]' or fuser_1='$values[username]')";
			 $result=mysql_query($sql);
			 $res=mysql_fetch_array($result);
			 $sql = "SELECT sum(money) AS count FROM pay_log where fuser<>'admin' and (code='$values[daili]' or fuser='$values[username]' or fuser_1='$values[username]')";
			 $result=mysql_query($sql);
			 $res1=mysql_fetch_array($result);
			 
			 //wtf
			 $sql = "SELECT sum(money) AS count FROM pay_log where TO_DAYS(time)=TO_DAYS(NOW()) and fuser<>'admin' and code='$values[daili]'";
			 $result=mysql_query($sql);
			 $res2=mysql_fetch_array($result);
			 $sql = "SELECT sum(money) AS count FROM pay_log where fuser<>'admin' and code='$values[daili]'";
			 $result=mysql_query($sql);
			 $res3=mysql_fetch_array($result);
			 
			 
			 
			 $today = $res['count'];
			 $fencheng=$today * $values['fencheng'] / 100;
			 $all = $res1['count'];
			 $today1 =$res2['count'];
			 $all1 = $res3['count'];
			 $fencheng1 = $all * $values['fencheng'] / 100;
			 if($today == ""){$today=0;}
			 if($all==""){$all=0;}
			 if($all1==""){$all1=0;}
			 if($today1==""){$today1=0;}
			 
			 echo"<tr class='text-c'>
			        <td>".$values['username']."</td>
			        <td>".$values['status']."</td>
			        <td>".$today."</td>
			        <td>".$today1."</td>
			        <td>".$fencheng."</td>
			        <td>".$fencheng1."</td>
			        <td>".$values['y_money']."</td>
			        <td>".$values['n_money']."</td>
			        </tr>
			        "
			        ;
			        
			}
			
?>
				
				</tr>
			</tbody>
		</table>
		
	</div>
</div>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="lib/hcharts/Highcharts/5.0.6/js/highcharts.js"></script>
<script type="text/javascript" src="lib/hcharts/Highcharts/5.0.6/js/modules/exporting.js"></script>
<script type="text/javascript" src="lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
<script type="text/javascript">
$('.table-sort').dataTable({
	"aaSorting": [[ 1, "desc" ]],//默认第几个排序
	"bStateSave": true,//状态保存
	"pading":false,
	"aoColumnDefs": [
	  //{"bVisible": false, "aTargets": [ 3 ]} //控制列的隐藏显示
	  {"orderable":false,"aTargets":[0]}// 不参与排序的列
	]
});
</script>
</body>
</html> 


      